//
//  SeleceLanaugeController.m
//  BCNADemo
//
//  Created by 马东朝 on 2018/5/16.
//  Copyright © 2018年 马东朝. All rights reserved.
//

#import "SeleceLanaugeController.h"
#define CellInd @"cell"
@interface SeleceLanaugeController ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *tableView;
}

@end

@implementation SeleceLanaugeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addTableView];
}
- (void)addTableView{
    
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.but.frame) + kHeight(100), ScreenWidth, ScreenHeight - CGRectGetMaxY(self.but.frame) - kHeight(100)) style:UITableViewStylePlain];
    tableView.scrollEnabled = NO;
    tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:tableView];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellInd];
    tableView.rowHeight = kHeight(180);
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
#pragma mark -- UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellInd];
    cell.backgroundColor = [UIColor clearColor];
    NSString *textStr = [NSString stringWithFormat:@"SeleceLanauge%ld", indexPath.row];
    
    if (indexPath.row == 0) {
        if ([lanagueStyle isEqualToString:@"China"]) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            cell.textLabel.textColor = [UIColor colorWithHexString:@"#40b5f8"];
            cell.tintColor = [UIColor colorWithHexString:@"#40b5f8"];
        }else{
            cell.textLabel.textColor = [UIColor whiteColor];
        }
        
    }else{
        if ([lanagueStyle isEqualToString:@"English"]) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            cell.textLabel.textColor = [UIColor colorWithHexString:@"#40b5f8"];
            cell.tintColor = [UIColor colorWithHexString:@"#40b5f8"];
        }else{
            cell.textLabel.textColor = [UIColor whiteColor];
        }
        
    }
    cell.textLabel.text = StringWithKey(textStr);
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#40b5f8"];
    cell.tintColor = [UIColor colorWithHexString:@"#40b5f8"];
    if (indexPath.row == 1) {
        [[NSUserDefaults standardUserDefaults] setValue:@"English" forKey:lanaugeKey];
        UITableViewCell *cell1 = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        cell1.accessoryType = UITableViewCellAccessoryNone;
        cell1.textLabel.textColor = [UIColor whiteColor];
        cell1.tintColor = [UIColor whiteColor];
        
    }else{
        [[NSUserDefaults standardUserDefaults] setValue:@"China" forKey:lanaugeKey];
        UITableViewCell *cell1 = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
        cell1.accessoryType = UITableViewCellAccessoryNone;
        cell1.textLabel.textColor = [UIColor whiteColor];
        cell1.tintColor = [UIColor whiteColor];
    }
    if ([self.delegate respondsToSelector:@selector(selectLanaugeWIthIndex:)]) {
        [self.delegate selectLanaugeWIthIndex:indexPath.row];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
